
//
//	cove.geom.ColorTransform - 2011 July 6th
//
//	The ColorTransform class lets you adjust the color values in a display object. The color
//	adjustment or color transformation can be applied to all four channels: red, green, blue, and
//	alpha transparency.
//
//-------------------------------------------------------------------------------------------------

var ColorTransform = cove.geom.ColorTransform = Class.extend({
	
	init: function(redMultiplier, greenMultiplier, blueMultiplier, alphaMultiplier, redOffset, greenOffset, blueOffset, alphaOffset) {
		this.redMultiplier = isNaN(redMultiplier) ? 1 : redMultiplier;
		this.greenMultiplier = isNaN(greenMultiplier) ? 1 : greenMultiplier;
		this.blueMultiplier = isNaN(blueMultiplier) ? 1 : blueMultiplier;
		this.alphaMultiplier = isNaN(alphaMultiplier) ? 1 : alphaMultiplier;
		this.redOffset = isNaN(redOffset) ? 0 : redOffset;
		this.greenOffset = isNaN(greenOffset) ? 0 : greenOffset;
		this.blueOffset = isNaN(blueOffset) ? 0 : blueOffset;
		this.alphaOffset = isNaN(alphaOffset) ? 0 : alphaOffset;
	},
	
	
//	Public properties
//-------------------------------------------------------------------------------------------------
	
	// The RGB color value for a ColorTransform object.
	get color() {
		return 65536 * this.redOffset + 256 * this.greenOffset + this.blueOffset;
	},
	set color(v) {
		this.blueOffset = v & 255;
		this.greenOffset = (v >> 8) & 255;
		this.redOffset = (v >> 16) & 255;
		this.blueMultiplier = 0;
		this.greenMultiplier = 0;
		this.redMultiplier = 0;
	},


//	Public methods
//-------------------------------------------------------------------------------------------------
	
	// An additive combination of the two color transformations.
	concat: function(colorTransform) {
		this.redMultiplier *= colorTransform.redMultiplier;
		this.greenMultiplier *= colorTransform.greenMultiplier;
		this.blueMultiplier *= colorTransform.blueMultiplier;
		this.alphaMultiplier *= colorTransform.alphaMultiplier;
		this.redOffset += colorTransform.redOffset;
		this.greenOffset += colorTransform.greenOffset;
		this.blueOffset += colorTransform.blueOffset;
		this.alphaOffset += colorTransform.alphaOffset;
	},
	
	// Formats and returns a string that describes all of the properties of the ColorTransform object.
	toString: function() {
		return (
			'(redMultiplier=' + this.redMultiplier +
			', greenMultiplier=' + this.greenMultiplier +
			', blueMultiplier=' + this.blueMultiplier +
			', alphaMultiplier=' + this.alphaMultiplier +
			', redOffset=' + this.redOffset +
			', greenOffset=' + this.greenOffset +
			', blueOffset=' + this.blueOffset +
			', alphaOffset=' + this.alphaOffset +
			')'
		);
	}

});
